/*     */ package com.qmsk.business.task.tryrecord.controller;
/*     */ 
/*     */ import com.qmsk.business.info.taskRemind.dao.TaskRemindDao;
/*     */ import com.qmsk.business.manage.user.dao.UserDAO;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.task.tryrecord.dao.TryRecordDao;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"tryRecord"})
/*     */ public class TryRecordController
/*     */ {
/*  36 */   private static final Logger logger = Logger.getLogger(TryRecordController.class);
/*     */ 
/*     */   @Autowired
/*     */   private TryRecordDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private UserDAO userDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private TaskRemindDao taskRemindDao;
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"insert/insertInfo"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response) { try { int nResult = 0;
/*  53 */       String sData = RequestUtils.getStringOfData(request);
/*  54 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*  55 */       if (p != null) {
/*  56 */         GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(0);
/*  57 */         g.autoAddHeadData("submitDate", new Date());
/*  58 */         g.autoAddHeadData("status", Integer.valueOf(0));
/*  59 */         nResult = this.dao.applyUpdates(p);
/*  60 */         if (nResult > 0) {
/*  61 */           Long userId = ObjectComm.objectToLong(g.getValueOfName("userId"));
/*  62 */           Long memberId = ObjectComm.objectToLong(g.getValueOfName("memberId"));
/*  63 */           Long shopId = ObjectComm.objectToLong(g.getValueOfName("shopId"));
/*  64 */           Long CustomerID = ObjectComm.objectToLong(g.getValueOfName("custID"));
/*  65 */           String customerName = ObjectComm.objectToString(g.getValueOfName("custName"));
/*  66 */           String trcTypeName = ObjectComm.objectToString(g.getValueOfName("trcTypeName"));
/*  67 */           String tryDate = ObjectComm.objectToString(g.getValueOfName("tryDate"));
/*  68 */           String timeName = ObjectComm.objectToString(g.getValueOfName("timeName"));
/*  69 */           String mp = ObjectComm.objectToString(g.getValueOfName("mp"));
/*  70 */           String custOpenId = this.memberDAO.getOpenId(CustomerID);
/*  71 */           GsonHeadOneRow user = this.userDao.selectUserById(userId);
/*  72 */           Long id = this.dao.getLastId();
/*  73 */           String content = "试乘试驾预约通知:\n客户姓名：" + customerName + "\n联系电话：" + mp + "\n预约时间：" + tryDate + " " + timeName + "\n试驾车型：" + trcTypeName;
/*  74 */           if (user != null) {
/*  75 */             String openId = (String)user.getValueOfName("openId");
/*  76 */             String name = (String)user.getValueOfName("name");
/*  77 */             String userMp = (String)user.getValueOfName("mp");
/*  78 */             if ((custOpenId != null) && 
/*  79 */               (StringUtils.isNotEmpty(custOpenId))) {
/*  80 */               WeiXinUtil.sendTextMessageOfMain("试乘试驾预约受理通知:\n尊敬的" + customerName + ",我们已经收到您的试乘试驾预约,我是您的销售顾问：" + name + ",\n联系电话：" + userMp, custOpenId);
/*     */             }
/*     */ 
/*  83 */             if ((StringUtils.isNotEmpty(openId)) && 
/*  84 */               (StringUtils.isNotEmpty(openId))) {
/*  85 */               WeiXinUtil.sendTextMessageOfMain(content, openId);
/*     */             }
/*     */ 
/*  88 */             String[] head = { "CreateTime", "AssignTime", "TaskMemo", "Status", "CustName", "Mp", "CustID", "MemberID", "ShopId", "AssignId", "AssignName", "RemindID", "taskDetilId" };
/*  89 */             Object[] data = { new Date(), new Date(), content, Integer.valueOf(1), customerName, mp, CustomerID, memberId, shopId, userId, name, Integer.valueOf(7), id };
/*  90 */             nResult = this.taskRemindDao.insertGsonHeadOneRow(new GsonHeadOneRow(head, data));
/*     */           }
/*     */           else {
/*  93 */             String[] head = { "CreateTime", "AssignTime", "TaskMemo", "Status", "CustName", "Mp", "CustID", "MemberID", "ShopId", "RemindID", "taskDetilId" };
/*  94 */             Object[] data = { new Date(), tryDate, content, Integer.valueOf(0), customerName, mp, CustomerID, memberId, shopId, Integer.valueOf(7), id };
/*  95 */             nResult = this.taskRemindDao.insertGsonHeadOneRow(new GsonHeadOneRow(head, data));
/*     */           }
/*  97 */           if (nResult > 0)
/*     */           {
/*  99 */             DbConnection.commit();
/*     */           }
/*     */           else DbConnection.rollback();
/*     */         }
/*     */         else
/*     */         {
/* 105 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 108 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 109 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 110 */         response);
/*     */     } catch (Exception e) {
/* 112 */       logger.error(e);
/* 113 */       DbConnection.rollback();
/* 114 */       ResponseUtils.setErrorMsgResponse(
/* 115 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 116 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 126 */       int nResult = 0;
/* 127 */       String sData = RequestUtils.getStringOfData(request);
/* 128 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 129 */       if (p != null) {
/* 130 */         nResult = this.dao.applyUpdates(p);
/* 131 */         if (nResult > 0)
/* 132 */           DbConnection.commit();
/*     */         else {
/* 134 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 137 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 138 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 139 */         response);
/*     */     } catch (Exception e) {
/* 141 */       logger.error(e);
/* 142 */       DbConnection.rollback();
/* 143 */       ResponseUtils.setErrorMsgResponse(
/* 144 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 145 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 153 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 155 */       String[] strParams = id.split(",");
/* 156 */       int nResult = this.dao.deleteParams(strParams);
/* 157 */       if (nResult > 0)
/* 158 */         DbConnection.commit();
/*     */       else {
/* 160 */         DbConnection.rollback();
/*     */       }
/* 162 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 163 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 164 */         response);
/*     */     } catch (Exception e) {
/* 166 */       DbConnection.rollback();
/* 167 */       logger.error(e);
/* 168 */       ResponseUtils.setErrorMsgResponse(
/* 169 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 170 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response)
/*     */     throws SQLException
/*     */   {
/* 179 */     String id = RequestUtils.getString(request, "id");
/* 180 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 181 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 182 */     int nResult = 0;
/*     */     try {
/* 184 */       nResult = this.dao.updateCheckedOfIds(userId, userName, id);
/* 185 */       if (nResult > 0)
/* 186 */         DbConnection.commit();
/*     */       else {
/* 188 */         DbConnection.rollback();
/*     */       }
/* 190 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 191 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 192 */         response);
/*     */     } catch (Exception e) {
/* 194 */       DbConnection.rollback();
/* 195 */       logger.error(e);
/* 196 */       ResponseUtils.setErrorMsgResponse(
/* 197 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 198 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/tryRecord/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 205 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 207 */       Map params = new HashMap();
/* 208 */       String shopId = RequestUtils.getString(request, "shopId");
/* 209 */       String openId = RequestUtils.getString(request, "openId");
/* 210 */       String id = RequestUtils.getString(request, "id");
/*     */ 
/* 212 */       MapUtils.addToMap(params, "shopId", shopId);
/* 213 */       MapUtils.addToMap(params, "openId", openId);
/* 214 */       MapUtils.addToMap(params, "id", id);
/* 215 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(params, nPageIdx, nPageSize);
/* 216 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 218 */       logger.error(e);
/* 219 */       ResponseUtils.setErrorMsgResponse(
/* 220 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/tryRecordOfUserId/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void tryRecordOfUserId(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 227 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 229 */       Map params = new HashMap();
/* 230 */       String shopId = RequestUtils.getString(request, "shopId");
/* 231 */       String userId = RequestUtils.getString(request, "userId");
/* 232 */       MapUtils.addToMap(params, "shopId", shopId);
/* 233 */       MapUtils.addToMap(params, "userId", userId);
/* 234 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(params, nPageIdx, nPageSize);
/* 235 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 237 */       logger.error(e);
/* 238 */       ResponseUtils.setErrorMsgResponse(
/* 239 */         RequestUtils.getFindDataErrorMessage(request), response); } }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"edit/deal"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void deal(HttpServletRequest request, HttpServletResponse response) {
/*     */     try {
/* 245 */       int nResult = 0;
/* 246 */       Long id = null;
/* 247 */       String sData = RequestUtils.getStringOfData(request);
/* 248 */       String reply = RequestUtils.getString(request, "reply");
/* 249 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 250 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 251 */         GsonHeadOneRow g = (GsonHeadOneRow)p.getListUpdateRows().get(0);
/* 252 */         g.autoInsertHeadData("CancelDate", new Date());
/* 253 */         g.autoInsertHeadData("replyDate", new Date());
/* 254 */         id = ObjectComm.objectToLong(g.getValueOfName("id"));
/* 255 */         String openId = this.dao.getOpenIdById(id);
/*     */ 
/* 257 */         nResult = this.dao.applyUpdates(p);
/* 258 */         if (nResult > 0) {
/* 259 */           DbConnection.commit();
/* 260 */           WeiXinUtil.sendTextMessageOfMain("试乘试驾预约处理情况:\n" + reply, openId);
/*     */         } else {
/* 262 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 265 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 266 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 267 */         response);
/*     */     } catch (Exception e) {
/* 269 */       logger.error(e);
/* 270 */       DbConnection.rollback();
/* 271 */       ResponseUtils.setErrorMsgResponse(
/* 272 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 273 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.task.tryrecord.controller.TryRecordController
 * JD-Core Version:    0.5.3
 */